package chess;

/**
 *
 * @author Anthony
 */
public class Pawn extends Piece
{
    
    public Pawn(int color)
    {
        pieceColor = color;
    }//end of constructor
    
    public int canMove(int sourceX, int sourceY, int destX, int destY)
    {
        // Return false if coordinates are outside of the board.
        if(sourceX < 0 || sourceX > 7 || sourceY < 0 || sourceY > 7 ||
                destX < 0 || destX > 7 || destY < 0 || destY > 7)
            return 0;
        
        if(sourceX == destX) // Piece is moving vertically
        {
            if(  (getColor() == 0 && destY - sourceY == 1) || // Piece is black
                 (getColor() == 1 && destY - sourceY == -1))  // Piece is white
            {
                return 1;
            }
        } else if(Math.abs(destX - sourceX) == 1) // Piece is moving diagonally
        {
            if(  (getColor() == 0 && destY - sourceY == 1) || // Piece is black
                 (getColor() == 1 && destY - sourceY == -1))  // Piece is white
            {
                return 2;
            } 
        }
        
        return 0;   
       
    }//end of canMove
    
    public char getType()
    {
        return 'P';
    }//end of getType
    
    public static int getValue()
    {
        return 1;
    }//end of getValue
    
    
}//end of Pawn
